| Conditions | 33 |
| Paths | 11712 |
| Total Lines | 112 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like AbstractAjaxPromises.ajaxRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | |||
| 81 | let type = ''; |
||
| 82 | switch (true) |
||
| 83 | { |
||
| 84 | case 'success' === textStatus && data && data.Result && action === data.Action: |
||
| 85 | type = StorageResultType.Success; |
||
| 86 | break; |
||
| 87 | case 'abort' === textStatus && (!data || !data.__aborted__): |
||
| 88 | type = StorageResultType.Abort; |
||
| 89 | break; |
||
| 90 | default: |
||
| 91 | type = StorageResultType.Error; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | |||
| 95 | Plugins.runHook('ajax-default-response', [ |
||
| 96 | action, StorageResultType.Success === type ? data : null, type, isCached, params |
||
| 97 | ]); |
||
| 98 | |||
| 99 | if ('success' === textStatus) |
||
| 100 | { |
||
| 101 | if (data && data.Result && action === data.Action) |
||
| 102 | { |
||
| 103 | data.__cached__ = isCached; |
||
| 104 | resolve(data); |
||
| 105 | } |
||
| 106 | else if (data && data.Action) |
||
| 107 | { |
||
| 108 | errorData = data; |
||
| 109 | reject(data.ErrorCode ? data.ErrorCode : Notification.AjaxFalse); |
||
| 110 | } |
||
| 111 | else |
||
| 112 | { |
||
| 113 | errorData = data; |
||
| 114 | reject(Notification.AjaxParse); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | else if ('timeout' === textStatus) |
||
| 118 | { |
||
| 119 | errorData = data; |
||
| 120 | reject(Notification.AjaxTimeout); |
||
| 121 | } |
||
| 122 | else if ('abort' === textStatus) |
||
| 123 | { |
||
| 124 | if (!data || !data.__aborted__) |
||
| 125 | { |
||
| 126 | reject(Notification.AjaxAbort); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | else |
||
| 130 | { |
||
| 131 | errorData = data; |
||
| 132 | reject(Notification.AjaxParse); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (this.oRequests[action]) |
||
| 136 | { |
||
| 137 | this.oRequests[action] = null; |
||
| 138 | delete this.oRequests[action]; |
||
| 139 | } |
||
| 140 | |||
| 141 | this.setTrigger(fTrigger, false); |
||
| 142 | |||
| 143 | if (errorData) |
||
| 144 | { |
||
| 145 | if (-1 < inArray(errorData.ErrorCode, [ |
||
| 146 | Notification.AuthError, Notification.AccessError, |
||
| 147 | Notification.ConnectionError, Notification.DomainNotAllowed, Notification.AccountNotAllowed, |
||
| 148 | Notification.MailServerError, Notification.UnknownNotification, Notification.UnknownError |
||
| 149 | ])) |
||
| 150 | { |
||
| 151 | GlobalsData.iAjaxErrorCount += 1; |
||
| 152 | } |
||
| 153 | |||
| 154 | if (Notification.InvalidToken === errorData.ErrorCode) |
||
| 155 | { |
||
| 156 | GlobalsData.iTokenErrorCount += 1; |
||
| 157 | } |
||
| 158 | |||
| 159 | if (TOKEN_ERROR_LIMIT < GlobalsData.iTokenErrorCount) |
||
| 160 | { |
||
| 161 | if (GlobalsData.__APP__ && GlobalsData.__APP__.loginAndLogoutReload) |
||
| 162 | { |
||
| 163 | GlobalsData.__APP__.loginAndLogoutReload(false, true); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | if (errorData.ClearAuth || errorData.Logout || AJAX_ERROR_LIMIT < GlobalsData.iAjaxErrorCount) |
||
| 168 | { |
||
| 169 | if (GlobalsData.__APP__ && GlobalsData.__APP__.clearClientSideToken) |
||
| 170 | { |
||
| 171 | GlobalsData.__APP__.clearClientSideToken(); |
||
| 172 | } |
||
| 173 | |||
| 174 | if (GlobalsData.__APP__ && !errorData.ClearAuth && GlobalsData.__APP__.loginAndLogoutReload) |
||
| 175 | { |
||
| 176 | GlobalsData.__APP__.loginAndLogoutReload(false, true); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | }); |
||
| 182 | |||
| 183 | if (oH) |
||
| 184 | { |
||
| 185 | if (this.oRequests[action]) |
||
| 186 | { |
||
| 187 | this.oRequests[action] = null; |
||
| 188 | delete this.oRequests[action]; |
||
| 189 | } |
||
| 190 | |||
| 191 | this.oRequests[action] = oH; |
||
| 192 | } |
||
| 193 | }); |
||
| 214 |